import { comments } from "../data";

export async function GET(request, { params }) {
  const { id } = await params;
  const comment = comments.find(c => c.id == parseInt(id));
  return Response.json(comment);
}


export async function PUT(request, { params }) {
  const { id } = await params;
  const body = await request.json()
  console.log(body,id);
  
  const index = comments.findIndex(c => c.id == parseInt(id));
  comments[index].text = body.text
  return Response.json(comments[index]);
}


export async function DELETE(request, { params }) {
  const { id } = await params;
  const index = comments.findIndex(c => c.id == parseInt(id));
  const deleteComment = comments[index]
  comments.splice(index,1)
  return Response.json(deleteComment);
}